package com.example.controller.User;

import com.example.pojo.VO.Result;
import com.example.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
@Slf4j
public class FileUploadController {
//    TODO 上传文件到阿里云，保存文件或者图片
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
        log.info("上传文件{}",file.getOriginalFilename());
        String originalFileName= file.getName();
        String fileName= UUID.randomUUID().toString()+originalFileName.substring(originalFileName.lastIndexOf("."));
        String url= AliOssUtil.UploadFile(fileName,file.getInputStream());
        log.info("获取路径{}",url);
        return Result.success(url);
    }
}
